################################################################
#Script: Analysis_DBP.R
################################################################
#Project: Gov 2001 Project; Do Businesses Pay to Do Science?; Extension of Giuri P. and Mariani M., "When Distance Disappears", 2013
#Script Goal: Load 
#Inputs: 
#- 'WIP/DataList.R' files outputted by 'Matching_DBP.R'
#Outputs: Analysis results used to calculate tables
###############################################################
rm(list=ls())

##Packages
#install.packages("Zelig")
#install.packages("ZeligChoice")
library(Zelig)
library(ZeligChoice)

##Working Directory, Temp Folder
root<-"ENTER YOUR WORKING DIRECTORY HERE"
setwd(root)

##Set Seed
set.seed(02127)

################################################################
#Load Data
################################################################
load(file="WIP/DataList.RData")
load(file="WIP/DataCemList.RData")

for (i in 1:length(data.balanced.cem.list)) {
  assign(paste("db",i,sep=""),data.balanced.list[[i]])
  assign(paste("dbc",i,sep=""),data.balanced.cem.list[[i]])
}

################################################################
#First Analysis: Science and Conferences
################################################################
################################################################
#NON-MATCHED RESULTS
################################################################
#Results of probit regressions w/nuts2 and nuts3 controls against Sci_dummy
################################################################
sci.probit.1 <- zelig(Sci_dummy~
                        Age +
                        Male +
                        PhDDegree +
                        link_coinv_diff_nuts_share1_b + 
                        no_pastcoinv +
                        DE_dummy +
                        CE_dummy +
                        year_first_patent +
                        residence_degree +
                        reg_mob_nuts3In +
                        reg_mob_nuts3Out +
                        herfinv1 +
                        zeroExp +
                        lEmployeesMiss + 
                        RDint +
                        Ninventors +
                        AppYear +
                        nuts2_d_res_country +
                        TechClass,
                      model = "probit",
                      data = mi(db1,db2,db3,db4,db5,db6,db7,db8,db9,db10),
                      robust = TRUE)
summary(sci.probit.1)

sci.probit.2 <- zelig(Sci_dummy~
                        Age +
                        Male +
                        PhDDegree +
                        link_coinv_diff_nuts_share1_b + 
                        no_pastcoinv +
                        DE_dummy +
                        CE_dummy +
                        year_first_patent +
                        residence_degree +
                        reg_mob_nuts3In +
                        reg_mob_nuts3Out +
                        herfinv1 +
                        zeroExp +
                        lEmployeesMiss + 
                        RDint +
                        Ninventors +
                        AppYear +
                        nuts3_d_res +
                        lgdppop_nuts3 +
                        lpop_nuts3 +
                        larea_nuts3_km2 +
                        lav_pat_nuts3_9496 +
                        top1_tc +
                        shangai_n_univ +
                        overall_score +
                        TechClass,
                      model = "probit",
                      data = mi(db1,db2,db3,db4,db5,db6,db7,db8,db9,db10),
                      robust = TRUE)
summary(sci.probit.2)

################################################################
#Results of probit regressions w/nuts2 and nuts3 controls against Conf_dummy
################################################################
conf.probit.1 <- zelig(Conf_dummy ~
                        Age +
                        Male +
                        PhDDegree +
                        link_coinv_diff_nuts_share1_b + 
                        no_pastcoinv +
                        DE_dummy +
                        CE_dummy +
                        year_first_patent +
                        residence_degree +
                        reg_mob_nuts3In +
                        reg_mob_nuts3Out +
                        herfinv1 +
                        zeroExp +
                        lEmployeesMiss + 
                        RDint +
                        Ninventors +
                        AppYear +
                        nuts2_d_res_country +
                        TechClass,
                      model = "probit",
                      data = mi(db1,db2,db3,db4,db5,db6,db7,db8,db9,db10),
                      robust = TRUE)
summary(conf.probit.1)

conf.probit.2 <- zelig(Conf_dummy~
                        Age +
                        Male +
                        PhDDegree +
                        link_coinv_diff_nuts_share1_b + 
                        no_pastcoinv +
                        DE_dummy +
                        CE_dummy +
                        year_first_patent +
                        residence_degree +
                        reg_mob_nuts3In +
                        reg_mob_nuts3Out +
                        herfinv1 +
                        zeroExp +
                        lEmployeesMiss + 
                        RDint +
                        Ninventors +
                        AppYear +
                        nuts3_d_res +
                        lgdppop_nuts3 +
                        lpop_nuts3 +
                        larea_nuts3_km2 +
                        lav_pat_nuts3_9496 +
                        top1_tc +
                        shangai_n_univ +
                        overall_score +
                        TechClass,
                      model = "probit",
                      data = mi(db1,db2,db3,db4,db5,db6,db7,db8,db9,db10),
                      robust = TRUE)
summary(conf.probit.2)

################################################################
#CEM RESULTS
################################################################
#Results of probit regressions w/nuts2 and nuts3 controls against Sci_dummy
################################################################
sci.cem.probit.1 <- zelig(Sci_dummy~
                        Age +
                        Male +
                        PhDDegree +
                        link_coinv_diff_nuts_share1_b + 
                        no_pastcoinv +
                        DE_dummy +
                        CE_dummy +
                        year_first_patent +
                        residence_degree +
                        reg_mob_nuts3In +
                        reg_mob_nuts3Out +
                        herfinv1 +
                        zeroExp +
                        lEmployeesMiss + 
                        RDint +
                        Ninventors +
                        AppYear +
                        nuts2_d_res_country +
                        TechClass,
                      model = "probit",
                      data = mi(dbc1,dbc2,dbc3,dbc4,dbc5,dbc6,dbc7,dbc8,dbc9,dbc10),
                      order.by=~w,
                      robust = TRUE)
summary(sci.cem.probit.1)

sci.cem.probit.2 <- zelig(Sci_dummy~
                        Age +
                        Male +
                        PhDDegree +
                        link_coinv_diff_nuts_share1_b + 
                        no_pastcoinv +
                        DE_dummy +
                        CE_dummy +
                        year_first_patent +
                        residence_degree +
                        reg_mob_nuts3In +
                        reg_mob_nuts3Out +
                        herfinv1 +
                        zeroExp +
                        lEmployeesMiss + 
                        RDint +
                        Ninventors +
                        AppYear +
                        nuts3_d_res +
                        lgdppop_nuts3 +
                        lpop_nuts3 +
                        larea_nuts3_km2 +
                        lav_pat_nuts3_9496 +
                        top1_tc +
                        shangai_n_univ +
                        overall_score +
                        TechClass,
                      model = "probit",
                      data = mi(dbc1,dbc2,dbc3,dbc4,dbc5,dbc6,dbc7,dbc8,dbc9,dbc10),
                      order.by=~w,
                      robust = TRUE)
summary(sci.cem.probit.2)

################################################################
#Results of probit regressions w/nuts2 and nuts3 controls against Conf_dummy
################################################################
conf.cem.probit.1 <- zelig(Conf_dummy ~
                         Age +
                         Male +
                         PhDDegree +
                         link_coinv_diff_nuts_share1_b + 
                         no_pastcoinv +
                         DE_dummy +
                         CE_dummy +
                         year_first_patent +
                         residence_degree +
                         reg_mob_nuts3In +
                         reg_mob_nuts3Out +
                         herfinv1 +
                         zeroExp +
                         lEmployeesMiss + 
                         RDint +
                         Ninventors +
                         AppYear +
                         nuts2_d_res_country +
                         TechClass,
                       model = "probit",
                       data = mi(dbc1,dbc2,dbc3,dbc4,dbc5,dbc6,dbc7,dbc8,dbc9,dbc10),
                       order.by=~w,
                       robust = TRUE)
summary(conf.cem.probit.1)

conf.cem.probit.2 <- zelig(Conf_dummy~
                         Age +
                         Male +
                         PhDDegree +
                         link_coinv_diff_nuts_share1_b + 
                         no_pastcoinv +
                         DE_dummy +
                         CE_dummy +
                         year_first_patent +
                         residence_degree +
                         reg_mob_nuts3In +
                         reg_mob_nuts3Out +
                         herfinv1 +
                         zeroExp +
                         lEmployeesMiss + 
                         RDint +
                         Ninventors +
                         AppYear +
                         nuts3_d_res +
                         lgdppop_nuts3 +
                         lpop_nuts3 +
                         larea_nuts3_km2 +
                         lav_pat_nuts3_9496 +
                         top1_tc +
                         shangai_n_univ +
                         overall_score +
                         TechClass,
                       model = "probit",
                       data = mi(dbc1,dbc2,dbc3,dbc4,dbc5,dbc6,dbc7,dbc8,dbc9,dbc10),
                       order.by=~w,
                       robust = TRUE)
summary(conf.cem.probit.2)

################################################################
#Second Analysis
################################################################
##Impact of Sci, Conf, PhD, UniMass on reasons

################################################################
#Results of probit regressions w/nuts2 and nuts3 controls against reasonCommExploit
################################################################

com.probit.1 <- zelig(Com_ratio ~
                             Age +
                             Male +
                             PhDDegree +
                             link_coinv_diff_nuts_share1_b + 
                             no_pastcoinv +
                             DE_dummy +
                             CE_dummy +
                             year_first_patent +
                             residence_degree +
                             reg_mob_nuts3In +
                             reg_mob_nuts3Out +
                             herfinv1 +
                             zeroExp +
                             lEmployeesMiss + 
                             RDint +
                             Ninventors +
                             AppYear +
                             nuts2_d_res_country +
                             TechClass,
                           model = "probit",
                            data = mi(db1,db2,db3,db4,db5,db6,db7,db8,db9,db10), 
                            order.by=~w,
                           robust = TRUE)
summary(com.probit.1)

com.probit.2 <- zelig(Com_ratio ~
                             Age +
                             Male +
                             PhDDegree +
                             link_coinv_diff_nuts_share1_b + 
                             no_pastcoinv +
                             DE_dummy +
                             CE_dummy +
                             year_first_patent +
                             residence_degree +
                             reg_mob_nuts3In +
                             reg_mob_nuts3Out +
                             herfinv1 +
                             zeroExp +
                             lEmployeesMiss + 
                             RDint +
                             Ninventors +
                             AppYear +
                             nuts3_d_res +
                             lgdppop_nuts3 +
                             lpop_nuts3 +
                             larea_nuts3_km2 +
                             lav_pat_nuts3_9496 +
                             top1_tc +
                             shangai_n_univ +
                             overall_score +
                             TechClass,
                           model = "probit",
                           #data = mi(dbc1,dbc2,dbc3,dbc4,dbc5,dbc6,dbc7,dbc8,dbc9,dbc10),
                           data = mi(db1,db2,db3,db4,db5,db6,db7,db8,db9,db10),
                           order.by=~w,
                           robust = TRUE)
summary(com.probit.2)

com.cem.probit.1 <- zelig(Com_ratio ~
                             Age +
                             Male +
                             PhDDegree +
                             link_coinv_diff_nuts_share1_b + 
                             no_pastcoinv +
                             DE_dummy +
                             CE_dummy +
                             year_first_patent +
                             residence_degree +
                             reg_mob_nuts3In +
                             reg_mob_nuts3Out +
                             herfinv1 +
                             zeroExp +
                             lEmployeesMiss + 
                             RDint +
                             Ninventors +
                             AppYear +
                             nuts2_d_res_country +
                             TechClass,
                           model = "probit",
                           data = mi(dbc1,dbc2,dbc3,dbc4,dbc5,dbc6,dbc7,dbc8,dbc9,dbc10),
                           order.by=~w,
                           robust = TRUE)
head(summary(com.cem.probit.1))

com.cem.probit.2 <- zelig(Com_ratio ~
                            Age +
                            Male +
                            PhDDegree +
                            link_coinv_diff_nuts_share1_b + 
                            no_pastcoinv +
                            DE_dummy +
                            CE_dummy +
                            year_first_patent +
                            residence_degree +
                            reg_mob_nuts3In +
                            reg_mob_nuts3Out +
                            herfinv1 +
                            zeroExp +
                            lEmployeesMiss + 
                            RDint +
                            Ninventors +
                            AppYear +
                            nuts3_d_res +
                            lgdppop_nuts3 +
                            lpop_nuts3 +
                            larea_nuts3_km2 +
                            lav_pat_nuts3_9496 +
                            top1_tc +
                            shangai_n_univ +
                            overall_score +
                            TechClass,
                          model = "probit",
                          data = mi(dbc1,dbc2,dbc3,dbc4,dbc5,dbc6,dbc7,dbc8,dbc9,dbc10),
                          order.by=~w,
                          robust = TRUE)

summary(com.cem.probit.2)

